<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('区域管理')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: datetimepicker-css"/>
</head>
<style>
    .bootstrap-tree-table .treetable-tbody td {
        white-space: normal !important;
    }

    .bootstrap-tree-table .treetable-bars .tool-right {
        float: left !important;
        left: 10px;
    }

    .table-striped .table > thead:first-child > tr:first-child > th {
        font-weight: normal;
        font-size: 13px;
        border: 1px solid #cccccc !important;
    }

    .bootstrap-tree-table .treetable-tbody td {
        border: 1px solid #cccccc !important;
        border-top: 0px solid #cccccc !important;
    }

    .select-list li p {
        width: 20px !important;
    }

</style>
<body class="gray-bg">

<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 项目名称
            </div>
            <div class="box-tools pull-right">
                <a type="button" class="btn btn-box-tool" href="#" onclick="project()" title="管理项目"><i
                        class="fa fa-edit"></i></a>
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i
                        class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i
                        class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新项目"><i
                        class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>

<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="region-form">
                    <input type="hidden" id="companyId" name="companyId">
                    <input type="hidden" id="companyName" name="companyName">
                    <input type="hidden" id="proId" name="proId">
                    <input type="hidden" id="programId" name="programId">
                    <input type="hidden" id="programName" name="programName">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p style="width: 90px !important;">项目名称：</p>
                                <input type="text" class="form-control" name="programName" id="progName"
                                       autocomplete='off'/>
                            </li>
                            <li style="margin-left: 50px">
                                <a class="btn btn-primary btn-rounded btn-sm" id="search" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">

                <a class="btn btn-success" id="add"
                   onclick="addView($('#companyId').val(),$('#proId').val(),$('#programName').val())">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                    <i class="fa fa-remove"></i> 删除
                </a>

                <a class="btn btn-warning" id="export" onclick="exportExcel('危大工程报表')">
                    <i class="fa fa-download"></i> 导出
                </a>

                <a class="btn btn-success" id="upload"
                   onclick="addInventory($('#companyId').val(),$('#proId').val(),$('#programName').val())">
                    <i class="fa fa-plus"></i> 清单录入
                </a>

                <a class="btn btn-success" id="download"
                   onclick="selectInventoryList($('#proId').val())">
                    <i class="fa fa-plus"></i> 清单下载
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: bootstrap-suggest-js"/>
<th:block th:include="include :: bootstrap-typeahead-js"/>


<script th:inline="javascript">

    /* 模块前缀url */
    var prefix = ctx + "danManage";

    var flag = true;

    /* 初始化方法 */
    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 300});

        $('#add').hide();
        $('#export').hide();
        $('#upload').hide();
        $('#download').hide();


        // 初始化列表
        queryList();

        // 初始化树组件
        queryProjectTree();
    });
    // $("#editButton").setAttribute('disabled',true)
    var companyId = $('#companyId').val();
    var proId = $('#proId').val();
    var programName = $('#programName').val();


    /* 初始化 列表信息 */
    function queryList() {
        var options = {
            uniqueId: "danId",
            url: prefix + "/list",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            pagination: true,
            modalName: "危大工程报表",
            columns: [
                [
                    {
                        checkbox: true,
                        rowspan: 2,
                        valign: "middle",
                        align: 'center',
                        width: "5%",
                    },
                    {
                        field: 'companyName',
                        align: 'center',
                        rowspan: 2,
                        title: '工程公司',
                        width: "5%",
                    },
                    {
                        field: 'programName',
                        align: 'center',
                        rowspan: 2,
                        title: '项目名称',
                        width: "5%",
                    },
                    {
                        field: 'projectContent',
                        align: 'center',
                        rowspan: 2,
                        title: '（超）危大</br>工程内容',
                        width: "5%",
                    },
                    {
                        field: 'scale',
                        align: 'center',
                        title: '规模',
                        rowspan: 2,
                        width: "8%",
                    },
                    {
                        field: 'note',
                        align: 'center',
                        title: '（超）危大</br>工程概述',
                        rowspan: 2,
                        width: "5%",
                        formatter: function (value, row, index) {
                            return $.table.tooltip(value, 10);
                        }
                    },
                    {
                        align: 'center',
                        title: '项目部编制会审',
                        rowspan: 1,
                        colspan: 2,
                        width: "5%",
                    },
                    {
                        align: 'center',
                        title: '工程公司审批',
                        rowspan: 1,
                        colspan: 2,
                        width: "5%",
                    },
                    {
                        align: 'center',
                        title: '建设集团审批',
                        rowspan: 1,
                        colspan: 3,
                        width: "5%",
                    },
                    {
                        align: 'center',
                        title: '专家论证',
                        rowspan: 1,
                        colspan: 3,
                        width: "5%",
                    },
                    {
                        align: 'center',
                        title: '安全技术交底',
                        rowspan: 1,
                        colspan: 2,
                        width: "5%",
                    },
                    {
                        field: 'startTime',
                        align: 'center',
                        title: '施工</br>开始时间',
                        rowspan: 2,
                        width: "5%",
                    },
                    {
                        field: 'updateBy',
                        align: 'center',
                        title: '创建人',
                        rowspan: 2,
                        width: "5%",
                    },
                    {
                        field: 'updateTime',
                        align: 'center',
                        title: '更新时间',
                        rowspan: 2,
                        width: "5%",
                        sortable: true,
                    },
                    {
                        title: '操作',
                        align: 'center',
                        rowspan: 2,
                        width: '20',
                        widthUnit: '%',
                        formatter: function (value, row, index) {
                            if (row.startTime != '') {
                                // 显示不置灰
                                if (!flag) {
                                    var html = $.common.sprintf('<a id="editButton"  class="btn btn-success btn-xs" href="javascript:void(0)" onclick="edit(\'' + row.danId + '\',\'' + $('#companyId').val() + '\',\'' + $('#proId').val() + '\')"><i class="fa fa-edit"></i>编辑</a><p>' +
                                        '<p><a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.danId + '\')"><i class="fa fa-remove"></i>删除</a>' +
                                        '<p><a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="detail(\'' + row.danId + '\')"><i class="fa fa-list-ul"></i>动态</a>', index, value);
                                    return html;
                                } else {
                                    var html = $.common.sprintf(
                                        '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.danId + '\')"><i class="fa fa-remove"></i>删除</a>' +
                                        '<p><a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="detail(\'' + row.danId + '\')"><i class="fa fa-list-ul"></i>动态</a>', index, value);
                                    return html;
                                }
                            } else {
                                // 显示不置灰
                                if (!flag) {
                                    var html = $.common.sprintf('<a id="editButton" class="btn btn-success btn-xs" href="javascript:void(0)" onclick="edit(\'' + row.danId + '\',\'' + $('#companyId').val() + '\',\'' + $('#proId').val() + '\')"><i class="fa fa-edit"></i>编辑</a><p>' +
                                        '<p><a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.danId + '\')"><i class="fa fa-remove"></i>删除</a>', index, value);
                                    return html;
                                } else {
                                    var html = $.common.sprintf(
                                        '<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.danId + '\')"><i class="fa fa-remove"></i>删除</a>', index, value);
                                    return html;
                                }
                            }
                        }
                    }],
                [
                    {
                        field: 'jointTime',
                        align: 'center',
                        title: '时间',
                        width: "5%",
                    },
                    {
                        field: 'jointStatus',
                        align: 'center',
                        title: '状态',
                        width: "5%",
                    },
                    {
                        field: 'companyTime',
                        align: 'center',
                        title: '时间',
                        width: "5%",
                    },
                    {
                        field: 'companyStatus',
                        align: 'center',
                        title: '状态',
                        width: "5%",
                    },
                    {
                        field: 'gmassTime',
                        align: 'center',
                        title: '时间',
                        width: "5%",
                    },
                    {
                        field: 'gmassStatus',
                        align: 'center',
                        title: '状态',
                        width: "5%",
                    },
                    {
                        field: 'companyFileVirtualPath',
                        align: 'center',
                        title: '附件',
                        width: "5%",
                        formatter: function (value, row, index) {
                            return '<a href="javascript:void(0)" onclick="openCompanyFile(\'' + $('#proId').val() + '\',\'' + row.danId + '\')">附件</a>';
                        }
                    },
                    {
                        field: 'masterTime',
                        align: 'center',
                        title: '时间',
                        width: "5%",
                    },
                    {
                        field: 'masterStatus',
                        align: 'center',
                        title: '状态',
                        width: "5%",
                    },
                    {
                        field: 'expertFilePath',
                        align: 'center',
                        title: '附件',
                        width: "5%",
                        formatter: function (value, row, index) {
                            return '<a href="javascript:void(0)" onclick="openExpertFile(\'' + $('#proId').val() + '\',\'' + row.danId + '\')">附件</a>';
                        }
                    },
                    {
                        field: 'discloseTime',
                        align: 'center',
                        title: '时间',
                        width: "5%",
                    },
                    {
                        field: 'discloseStatus',
                        align: 'center',
                        title: '状态',
                        width: "5%",
                    },

                ]
            ]
        };
        $.table.init(options);
    }

    /* 初始化 树组件 */
    function queryProjectTree() {
        var fix = ctx + "danManage";
        var url = fix + "/treeData?menu=wdgc";
        var options = {
            url: url,
            expandLevel: 0,
            onClick: zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            if (treeNode.grade == 1) {

                $("#companyId").val(treeNode.id);
                $("#proId").val("");
                $('#add').hide();
                $('#upload').hide();
                $('#export').show();
                $('#download').hide();
                flag = true;

                $("#programId").val("");
                $("#programName").val("");
                $.table.search()

            } else if (treeNode.grade == 2) {
                flag = false;
                $("#companyId").val(treeNode.pId);
                $("#proId").val(treeNode.id);
                $("#programId").val(treeNode.id);
                $("#programName").val(treeNode.name);
                $('#add').show();
                $('#upload').show();
                $('#export').show();
                $('#download').show();
                $.table.search()
            }
        }
    }

    /* 添加按钮 */
    function addView(companyId, proId, programName) {
        var url = "/danManage/add?companyId=" + companyId + "&proId=" + proId + "&programName=" + programName;
        $.modal.open("添加" + table.options.modalName, url);
    }

    /* 添加工程清单 */
    function addInventory(companyId, proId, programName) {
        var url = "/danManage/addInventory?companyId=" + companyId + "&proId=" + proId + "&programName=" + programName;
        $.modal.open("添加" + table.options.modalName, url);
    }

    /* 添加工程下载 */
    function selectInventoryList(programId) {
        $.modal.open("(超)危大工程清单下载", prefix + "/inventoryView?proId=" + programId + "&danId=0&type=0");
    }

    /* 集团附件下载 */
    function openCompanyFile(programId, danId) {
        $.modal.open("集团附件下载", prefix + "/inventoryView?proId=" + programId + "&danId=" + danId + "&type=1");
    }

    /* 专家附件下载 */
    function openExpertFile(programId, danId) {
        $.modal.open("专家附件下载", prefix + "/inventoryView?proId=" + programId + "&danId=" + danId + "&type=2");
    }

    /* 编辑按钮 */
    function edit(danId, companyId, proId) {
        var url = prefix + '/editListView?danId=' + danId + "&companyId=" + companyId + "&programId=" + proId;
        $.modal.open("报表编辑", url);
    }

    /* 导出按钮 */
    function exportExcel(fileName) {
        var data = {
            companyId: $("#companyId").val(),
            programId: $("#programId").val(),
            programName: $("#progName").val(),
        }

        $.modal.confirm("确定导出所有" + table.options.modalName + "吗？", function () {
            $.modal.loading("正在导出数据，请稍后...");
            $.post(table.options.exportUrl, data, function (result) {
                if (result.code == web_status.SUCCESS) {
                    window.location.href = ctx + "common/download?fileName=" + fileName + ".xls&delete=" + true;
                } else if (result.code == web_status.WARNING) {
                    $.modal.alertWarning(result.msg)
                } else {
                    $.modal.alertError(result.msg);
                }
                $.modal.closeLoading();
            });
        });
    }

    /* 初始化树组件 > 展开 */
    $('#btnExpand').click(function () {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    /* 初始化树组件 > 折叠 */
    $('#btnCollapse').click(function () {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    /* 初始化树组件 > 刷新 */
    $('#btnRefresh').click(function () {
        queryProjectTree();
    });

    /*动态详情-详细*/
    function detail(danId) {
        var url = prefix + '/detail/' + danId;
        $.modal.openTab("动态详情", url);
    }

    // 下载清单按钮
    function downloadFile(value) {
        window.location.href = "/common/download/resource?resource=" + value;
    }


</script>
</body>
</html>